package com.hyk.controller;

import com.hyk.dto.ApiResult;
import com.hyk.utils.QiniuUtil;
import com.hyk.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("/upload")
@Api(tags = "上传控制类")
@CrossOrigin
public class UploadController {

    private static final String perfix = "http://qpuevq2yq.hn-bkt.clouddn.com/";

    @PostMapping("/doUpLoad")
    @ApiOperation("上传文件")
    public ApiResult upload(@RequestBody MultipartFile file) throws IOException {

        String newFileName = UUID.randomUUID().toString().replaceAll("-","");
        String fileSrc = QiniuUtil.byteUpLoad(file.getBytes(),newFileName);
        return R.ok(perfix+fileSrc);
    }

}
